import dayjs from 'dayjs';
const formaDateHms = (time) => {
    let formatTime;
  if (time !== null) {
    const date = new Date(time);
    formatTime = dayjs(date).format('YYYY-MM-DD HH:mm');
  } else {
    formatTime = '-';
  }
  return formatTime;
}

const formaDateH = (time) => {
    let formatTime;
  if (time !== null) {
    const date = new Date(time);
    formatTime = dayjs(date).format('YYYY-MM-DD HH');
  } else {
    formatTime = '-';
  }
  return formatTime;
}

const statusTransformText = (status) => {
  switch (status) {
    case '1':
      return '无'
      break;
    case '2':
      return '运转'
      break;
    case '3':
      return '停止'
      break;
    case '4':
      return '异常'
      break;
    case '5':
      return '模块异常'
      break;
  
    default:
      return '-'
      break;
  }
}

 //分钟转换为多少天多少小时多少分钟
 const plusTimeStamp = (StatusMinute) => {
  if(StatusMinute>0){
    var day=parseInt(StatusMinute/60/24);
    var hour=parseInt(StatusMinute/60%24);
    var min= parseInt(StatusMinute % 60);
    StatusMinute="";
    if (day > 0){
        StatusMinute= day + "天";
    }
    if (hour>0){
        StatusMinute += hour + "小时";
    } 
    if (min>0){
        StatusMinute += parseFloat(min) + "分";
    }
     return StatusMinute;

  }else if(StatusMinute<0){
    Math.abs(StatusMinute)
    let num = Math.abs(StatusMinute);
    var day=parseInt(num/60/24);
    var hour=parseInt(num/60%24);
    var min= parseInt(num % 60);
    num="";
    if (day > 0){
      num = day + "天";
    } 
    if(day>6){//当day大于7的时候，return;
      num = day + "天";
      return num;
    }
    if (hour>0){
      num += hour + "小时";
    }
    if(min>0){
      num += parseFloat(min) + "分";
    }
     return num;
  }
}

const LastdepFn = (dep) => {
  if (dep) {
    let arr = dep.split('/')
    return arr[arr.length - 1]
  }
}
export default {
    formaDateH,
    formaDateHms,
    statusTransformText,
    plusTimeStamp,
    LastdepFn
}